/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ronsicecream.pos.master.process;

import com.buanalintas.bynga.Action;
import com.buanalintas.bynga.Controller;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Page;
import com.buanalintas.bynga.Utility;
import com.ronsicecream.pos.entities.PosMasterProcess;
import com.ronsicecream.pos.entities.PosMasterProcessDetail;
import com.ronsicecream.pos.master.processdetail.ProcessDetail;
import java.math.BigDecimal;
import java.util.List;

/**
 *
 * @author user
 */
public class Process extends Page{
    private Field processId;
    
    private Field processNumber;
    
    private Field processName;
    
    private Field processItemId;
    
    private Field processTotal;
    
    private Field processCost;
    
    private Field processDescription;
    
    private Field processGrandTotal;
    

    public Process() {
        super();

        setTheClass(PosMasterProcess.class);
        setPageDetail(ProcessDetail.class);
        
        
        processId = new Field();
        processId.setName("processId");
        processId.setCaption(" id");
        //opnameId.setInfo("opname id");
        processId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        processId.setInputProperties(" size=\"20\"");        
        getFields().add(processId);
        
        processItemId = new Field();
        processItemId.setName("processItemId");
        processItemId.setCaption("item");
        processItemId.setRequired(true);
        processItemId.setListProperties(" align=\"left\" width=\"15%\" nowrap");
        processItemId.setInputProperties(" size=\"30\" ");      
        processItemId.getSelectorColumns().add(new String[]{"itemCode", " Code", "width=\"10%\" nowrap"});
        processItemId.getSelectorColumns().add(new String[]{"itemName", " Name", "width=\"20%\""});
        processItemId.getSelectorColumns().add(new String[]{"itemMinimum", " Minimum", "width=\"20%\" nowrap"});
        processItemId.getSelectorColumns().add(new String[]{"itemSatuanId", " Satuan", "width=\"200%\""});
        processItemId.getSelectorColumns().add(new String[]{"itemSatuanOrder", " Satuan Order", "width=\"200%\""});
        processItemId.getSelectorColumns().add(new String[]{"itemTypeId", " Type", "width=\"20%\""});
        processItemId.setSelectorOrder("t.itemName");        
        getFields().add(processItemId);
        
        processName = new Field();
        processName.setName("processName");
        processName.setCaption("name");
        processName.setRequired(true);
        processName.setListProperties(" align=\"left\" width=\"15%\" nowrap");
        processName.setInputProperties(" size=\"30\" ");        
        getFields().add(processName);
        
        processNumber = new Field();
        processNumber.setName("processNumber");
        processNumber.setCaption("number");
        processNumber.setRequired(true);
        processNumber.setListProperties(" align=\"left\" width=\"15%\" nowrap");
        processNumber.setInputProperties(" size=\"30\" ");        
        getFields().add(processNumber);
        
        processTotal = new Field();
        processTotal.setName("processTotal");
        processTotal.setCaption("total");
        processTotal.setRequired(true);
        processTotal.setListProperties(" align=\"center\" width=\"5%\" nowrap");
        processTotal.setInputProperties(" size=\"8\" ");
        getFields().add(processTotal);
        
        processCost = new Field();
        processCost.setName("processCost");
        processCost.setCaption("cost");
        processCost.setRequired(true);
        processCost.setDefaultValue(0);
        processCost.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        processCost.setInputProperties(" size=\"20\"");        
        getFields().add(processCost);
        
        processDescription = new Field();
        processDescription.setName("processDescription");
        processDescription.setCaption("description");
        //opnameDescription.setInfo("opname description");
        processDescription.setListProperties(" width=\"55%\"");
        processDescription.setInputProperties(" cols=\"50\" rows=\"5\"");
        processDescription.setInputType(Field.INPUT_TEXT_AREA);
        processDescription.setInputCase(Field.CASE_UPPER);        
        getFields().add(processDescription);
        
        processGrandTotal = new Field();
        processGrandTotal.setName("processGrandTotal");
        processGrandTotal.setCaption("Grant total");
        //opnameTimestamp.setInfo("opname timestamp");
        processGrandTotal.setListProperties(" align=\"center\" width=\"6%\" nowrap");
        processGrandTotal.setInputProperties(" size=\"12\"");
        //opnameTimestamp.setFormatter(DateFormatter.getInstanceDateTime(this));
        getFields().add(processGrandTotal);
        
        getActions().add(Action.TRANS_ADD);
        getActions().add(Action.TRANS_EDIT);
        getActions().add(Action.TRANS_VIEW);
        fillFields();

        getFieldsAdd().clear();
        getFieldsAdd().add(processName);
        getFieldsAdd().add(processItemId);
//        getFieldsAdd().add(processCost);
//        getFieldsAdd().add(processGrandTotal);
        getFieldsAdd().add(processDescription);

        getFieldsEdit().clear();
        getFieldsEdit().add(processName);
        getFieldsEdit().add(processItemId);
//        getFieldsEdit().add(processCost);
//        getFieldsEdit().add(processTotal);
        getFieldsEdit().add(processDescription);

        getFieldsList().clear();
        getFieldsList().add(processName);
        getFieldsList().add(processItemId);
//        getFieldsList().add(processTotal);
//        getFieldsList().add(processCost);
//        getFieldsList().add(processGrandTotal);
        getFieldsList().add(processDescription);

        getFieldsView().clear();
        getFieldsView().add(processNumber);
        getFieldsView().add(processName);
//        getFieldsView().add(processTotal);
//        getFieldsView().add(processCost);
//        getFieldsView().add(processGrandTotal);
        getFieldsView().add(processDescription);

        setController(new ProcessController(this));
        setExportList(getClass().getResourceAsStream("ProsessList.jasper"));
        setExport(getClass().getResourceAsStream("Prosess.jasper"));
    }
    
     class ProcessController extends Controller {

        public ProcessController(Page page) {
            super(page);
            setOrder(processName);
            setOrderType("DESC");
        }

//        @Override
//        public void beforeInsert(Object data, List list) {
//            PosMasterProcess process = (PosMasterProcess) data;
//            
//            BigDecimal total = BigDecimal.ZERO;
//            BigDecimal grandtotal = BigDecimal.ZERO;
//            
//            for(Object detail : list){
//                PosMasterProcessDetail processDetail = (PosMasterProcessDetail) detail;
//                total =  total.add(processDetail.getProcessDetailTotal());
//                
//                
//                
//            }
//            grandtotal = total.add(process.getProcessCost());
//            process.setProcessGrandTotal(grandtotal);
//            process.setProcessTotal(total);
//        }

        
        
        
     }
}
